import { InputQuestion, QuestionBase, TimeQuestion, SelectQuestion, TextTable, TableBase } from '@/components/public-template';
import { Api } from '@/config/api/archivesReturn';
import { DMS_ARCHIVES_FILE_RETURN_STATUS_COLOR } from '@/filters/color';
import { regExp } from '@/utils/regExp';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'billCode',
        label: '单据编号',
        placeholder: '请输入',
        reg: regExp.strLen20,
        prompt: '输入字符需小于20'
      }),
      new InputQuestion({
        key: 'fileName',
        label: '文件名称',
        placeholder: '请输入',
        reg: regExp.len100,
        prompt: '输入字符需小于100'
      }),
      new SelectQuestion({
        key: 'status',
        label: '状态',
        value: [],
        type: 'dictionary',
        state: {
          mode: 'multiple',
          filterName: 'DMS_ARCHIVES_FILE_RETURN_STATUS'
        }
      }),
      new TimeQuestion({
        key: 'startTime',
        label: '申请时间',
        state: {
          showTime: true,
          keySplit: ['startTime', 'endTime'],
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss'
        }
      })
    ];
    return questions;
  }

  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        value: '序号',
        type: 'index'
      }),
      new TextTable({
        key: 'billCode',
        value: '单据编号',
        type: 'router',
        state: {
          type: 'url',
          url: 'ArchivesManageAddReturn',
          params: [{ id: 'id' }, { processInstanceId: 'approveId' }],
          state: {
            assign: { showType: 'VIEW' }
          }
        }
      }),
      new TextTable({
        key: 'fileName',
        value: '文件名称'
      }),
      new TextTable({
        key: 'status',
        value: '状态',
        type: 'dictionary',
        state: {
          mode: 'multiple',
          filterName: 'DMS_ARCHIVES_FILE_RETURN_STATUS'
        },
        colors: DMS_ARCHIVES_FILE_RETURN_STATUS_COLOR
      }),
      new TextTable({
        key: 'creatorName',
        value: '申请人'
      }),
      new TextTable({
        key: 'createdTime',
        value: '申请时间'
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        handle: [
          {
            type: 'hint',
            text: '撤回',
            class: 'text-primary',
            url: Api.archivesReturnInfoRevoke,
            postType: 'post-form',
            params: [{ id: 'id' }],
            urlName: 'id',
            state: {
              hintData: {
                title: '是否确认撤销？'
              }
            },
            showKey: [{ key: 'status', value: 3 }]
          },
          // {
          //   type: 'url',
          //   url: 'ArchivesManageAddReturn',
          //   text: '归还确认',
          //   class: 'text-primary',
          //   params: [{ id: 'id' }, { processInstanceId: 'approveId' }],
          //   state: {
          //     params: { showType: 'CONFIRM' }
          //   },
          //   showKey: [{ key: 'status', value: 3 }]
          // },
          {
            type: 'hint',
            text: '关闭流程',
            class: 'text-primary',
            url: Api.archivesReturnInfoCloseFlow,
            postType: 'post-form',
            params: [{ id: 'id' }],
            urlName: 'id',
            state: {
              hintData: {
                title: '是否关闭流程，关闭后，流程中断，不能再被重新发起？'
              }
            },
            showKey: [{ key: 'status', value: 2 }]
          },
          {
            type: 'hint',
            text: '删除',
            class: 'text-primary',
            url: Api.archivesReturnInfoDelete,
            postType: 'post-form',
            params: [{ id: 'id' }],
            urlName: 'id',
            state: {
              hintData: {
                title: '是否删除？'
              }
            },
            showKey: [{ key: 'status', value: 1 }]
          }
        ]
      })
    ];
    return tables;
  }
}

export default new HomeService();
